package com.kele.stream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author kele
 * @date 2021/10/12 15:40
 * @description
 * Stream 流式计算
 */
public class StreamTest {
    static List<User> userList=null;
    static  {
        User user1=new User(1,"可乐1",20);
        User user2=new User(2,"可乐2",21);
        User user3=new User(3,"可乐3",22);
        User user4=new User(4,"可乐4",23);
        User user5=new User(5,"可乐5",24);
        userList= Arrays.asList(user1, user2, user3, user4, user5);
    }


    public static void main(String[] args) {
        Stream<User> stream = userList.stream();
        stream.filter(user -> {return user.getId()%2==0;})
                .filter(user ->{return user.getAge()>20;})
                .map(user -> {return user.getName().toUpperCase();})
                .sorted((u1,u2)->{
                    return u2.compareTo(u1);
                })
                .forEach(System.out::println);
    }
}
